package 通过XML形式配置AOP;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

//声明为一个bean 声明为一个切面   可以通过O
public class CaculatorAspect {
	
	
	
	
	public void beforeMethod(JoinPoint joinPoint) {
		System.out.println("切面方法之前"); 
		System.out.println("函数名"+joinPoint.getSignature().getName() + "参数:"+joinPoint.getArgs());
	}
	
	//所有方法都触发
//	@Before("execution(void AOP.MyCaculatorInterFace.*(double , double))")
//	public void beforeMul() {
//		// TODO Auto-generated method stub
//		System.out.println("所有方法都触发");
//	}
	
	
		public void afterMethod(JoinPoint joinPoint) {
			System.out.println("add切面¸方法之后"); 
			System.out.println("函数名"+joinPoint.getSignature().getName() + "参数:"+joinPoint.getArgs());
		}
	
	
	public void returningMethod(JoinPoint joinPoint,Object result) {
		System.out.println("正常方法执行完之后"+joinPoint.getSignature().getName()+"返回值"+result);
	}
	
	
	public void afterThrowing(JoinPoint jPoint,Exception e) {
		System.out.println("捕获异常通知");
	}
	
	
	public Object aroundMethod(ProceedingJoinPoint pjd) {
		Object result = null;
		String methodName = pjd.getSignature().getName();
		//控制执行方法
		try {
			System.out.println("环绕:方法执行之前");
			result = pjd.proceed();
			System.out.println("环绕:方法执行之后");
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
}
